package gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSlider;

import animation.AnimationFrame;

public class TableAppFrame extends JFrame implements ActionListener
{

	private static final long serialVersionUID = 8541445868403871171L;
	
	private TablePanel tablePanel;
	private JSlider slider;
	private JButton _saveFrame;
	private JButton _done;
	private JButton _open;

	public TableAppFrame(int x, int y)
	{
		AnimationFrame.setWidth(x);
		AnimationFrame.setHeight(y);
		
		this.setSize(650, 450);
		this.setResizable(false);
		this.setBackground(Color.WHITE);
		this.setLayout(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		this.tablePanel = new TablePanel(x, y);
		tablePanel.setLocation(25, 25);
		this.add(tablePanel);
		
		this.slider = new JSlider();
		this.slider.setMaximum(256);
		this.slider.setMinimum(1);
		this.slider.setMajorTickSpacing(32);
		this.slider.setMinorTickSpacing(4);
		this.slider.setName("Frame Delay (ms)");
		this.slider.setPaintTicks(true);
		this.slider.setPaintTrack(true);
		this.slider.setSnapToTicks(false);
		
		this.slider.setLocation(30, 375);
		this.slider.setSize(440, 25);
		this.add(slider);
		
		this._saveFrame = new JButton("Save Frame");
		this._saveFrame.addActionListener(this);
		this._saveFrame.setSize(120, 25);
		this._saveFrame.setLocation(500, 25);
		this.add(_saveFrame);
		
		this._done = new JButton("Done");
		this._done.addActionListener(this);
		this._done.setSize(120, 25);
		this._done.setLocation(500, 55);
		this.add(_done);

		this._open = new JButton("Open");
		this._open.addActionListener(this);
		this._open.setSize(120, 25);
		this._open.setLocation(500, 85);
		this.add(_open);
		
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent act) {
		if(act.getActionCommand().equals("Save Frame"))
		{
			doSaveFrameAction();
		}
		else if(act.getActionCommand().equals("Done"))
		{
			doDoneAction();
		}
		else if(act.getActionCommand().equals("Open"))
		{
			doOpenAction();
		}
		
	}

	private void doOpenAction() {
		// TODO Auto-generated method stub
		System.out.println("Open pressed");
	}

	private void doDoneAction() {
		// TODO Auto-generated method stub
		System.out.println("Done pressed");
	}

	private void doSaveFrameAction() {
		System.out.println("Save pressed");
		
		this.tablePanel.grabFrame(true);
		
		//tablePanel.getStates();
		
	}
	
	
	
	
}
